home *** CD-ROM | disk | FTP | other *** search
/ HamCall (April 1991) / HAMCALL CD-ROM (Buckmaster)(April 1991).BIN / prgming / ctutor / uplow.c < prev    next >
Text File  |  1990-10-14  |  1KB  |  53 lines

  1.                                         /* Chapter 13 - Program 1 */
  2. #include "STDIO.H"
  3. #include "ctype.h"      /* Note - your compiler may not need this */
  4.  
  5. main()
  6. {
  7. FILE *fp;
  8. char line[80], filename[24];
  9. char *c;
  10.  
  11.    printf("Enter filename -> ");
  12.    scanf("%s",filename);
  13.    fp = fopen(filename,"r");
  14.  
  15.    do {
  16.       c = fgets(line,80,fp);   /* get a line of text */
  17.       if (c != NULL) {
  18.          mix_up_the_chars(line);
  19.       }
  20.    } while (c != NULL);
  21.  
  22.    fclose(fp);
  23. }
  24.  
  25. mix_up_the_chars(line)   /* this function turns all upper case
  26.                             characters into lower case, and all
  27.                             lower case to upper case. It ignores
  28.                             all other characters.               */
  29. char line[];
  30. {
  31. int index;
  32.  
  33.    for (index = 0;line[index] != 0;index++) {
  34.       if (isupper(line[index]))     /* 1 if upper case */
  35.          line[index] = tolower(line[index]);
  36.       else {
  37.          if (islower(line[index]))  /* 1 if lower case */
  38.             line[index] = toupper(line[index]);
  39.       }
  40.    }
  41.    printf("%s",line);
  42. }
  43.  
  44.  
  45.  
  46. /* Result of execution
  47.  
  48. (The selected file is displayed on the monitor with all of
  49.   the upper case characters converted to lower case, and all
  50.   of the lower case characters converted to upper case.)
  51.  
  52. */
  53.